import 'package:number_spark_flutter/widgets/brick/ns_brick.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../style/ns_style.dart';

class NSBottomBar extends StatelessWidget {
  NSBottomBar({Key? key, this.index = 0, required this.items}) : super(key: key);
  final int index;
  final List<NSBottomBarItem> items;

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.bottomCenter,
      children: [
        NSImage(
          assetImage: 'img_bg_main_bottom.png',
          width: double.infinity,
          height: 117.w,
        ),
        Container(
          padding: EdgeInsets.only(bottom: ScreenUtil().bottomBarHeight),
          height: 117.w,
          child: Row(
            children: List.generate(
                items.length,
                (index) => _buildItemView(
                      i: index,
                      item: items.elementAt(index),
                    )).toList(),
          ),
        ),
      ],
    );
  }

  Widget _buildItemView({required int i, required NSBottomBarItem item}) => Expanded(
        child: GestureDetector(
          onTap: () {
            if (item.onClick != null) item.onClick!(i);
          },
          behavior: HitTestBehavior.translucent,
          child: Stack(
            alignment: Alignment.center,
            children: [
              Positioned(
                top: 40.h,
                child: NSImage(
                  assetImage: i == index ? item.selectedImgRes : item.unselectedImgRes,
                  fit: BoxFit.contain,
                  width: item.imgWidth,
                  height: item.imgHeight,
                ),
              ),
            ],
          ),
        ),
      );
}

class NSBottomBarItem {
  final String selectedImgRes;
  final String unselectedImgRes;
  final String label;
  final TextStyle? selectedStyle;
  final TextStyle? unselectedStyle;
  final double imgWidth;
  final double imgHeight;
  final Function(int index)? onClick;
  final Stream<int>? steam;
  final int? count;

  NSBottomBarItem(
      {required this.selectedImgRes,
      required this.unselectedImgRes,
      required this.label,
      this.selectedStyle,
      this.unselectedStyle,
      required this.imgWidth,
      required this.imgHeight,
      this.onClick,
      this.steam,
      this.count});
}
